﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Aspect.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Interfaces;

namespace Twodi.Aspect.Implemented
{
    /// <summary>
    /// Define um componente que possui bounds.
    /// </summary>
    public class BoundsAspect : DependentAspect<IBoundsAspect>, IBounds
    {
        /// <summary>
        /// Bounds do componente.
        /// </summary>
        private Rectangle bounds;

        /// <summary>
        /// Construtor padrão.
        /// </summary>
        /// <param name="component"></param>
        public BoundsAspect(IBoundsAspect component)
            : base(component)
        {
            bounds = new Rectangle(this.Component.PositionProperties.Point.X, this.Component.PositionProperties.Point.Y, (int)this.Component.SizeProperties.Width, (int)this.Component.SizeProperties.Height);
            component.SizeProperties.SizeChanged += new EventHandler(UpdateBounds);
            component.PositionProperties.PositionChanged += new EventHandler<Args.PositionChangedEventArgs>(UpdateBounds);
            component.RotationProperties.OriginChanged += new EventHandler(UpdateBounds);
        }

        void UpdateBounds(object sender, EventArgs e)
        {
            bounds.X = this.Component.PositionProperties.Point.X - (int)this.Component.RotationProperties.Origin.X;
            bounds.Y = this.Component.PositionProperties.Point.Y - (int)this.Component.RotationProperties.Origin.Y;
            bounds.Width = (int)this.Component.SizeProperties.Width;
            bounds.Height = (int)this.Component.SizeProperties.Height;
        }

        /// <summary>
        /// Bounds do componente.
        /// </summary>
        public Rectangle Bounds
        {
            get
            {
                return bounds;
            }
        }
    }
}
